<?php include TMPL_PATH.'public/header.phtml';?>
<link rel="stylesheet" type="text/css" href="/statics/js/calendar/jscal2.css"/>
<link rel="stylesheet" type="text/css" href="/statics/js/calendar/border-radius.css"/>
<link rel="stylesheet" type="text/css" href="/statics/js/calendar/win2k.css"/>
<script type="text/javascript" src="/statics/js/calendar/calendar.js"></script>
<script type="text/javascript" src="/statics/js/calendar/lang/zh-cn.js"></script>
<style type="text/css">
</style>
<title></title>
<?php if(!$_REQUEST['is_ajax']):?>
<div class="subnav">
    <form name="searchform" action="<?php echo U('order/order_list');?>"  method="post">
    <div class="content-menu ib-a blue line-x">
    	<div style="float:left;margin-right:50px;">
        <a href='javascript:;' onclick="ButtonSelect('all');" class="on"><em <?php if($buttonselect=='all')echo 'style="font-size:18px;"';?> >全部订单</em></a>
        <a href='javascript:;' onclick="ButtonSelect('wait');" class="on" title="支付时间未满24小时的订单"><em <?php if($buttonselect=='wait')echo 'style="font-size:18px;"';?> >等待中的订单</em></a>
        <a href='javascript:;' onclick="ButtonSelect('ok');" class="on" title="已支付的正常可处理订单"><em <?php if($buttonselect=='ok')echo 'style="font-size:18px;"';?> >已支付的订单</em></a>
        <a href='javascript:;' onclick="ButtonSelect('pause');" class="on" title="所有暂停的订单,需要跟进"><em <?php if($buttonselect=='pause')echo 'style="font-size:18px;"';?> >暂停的订单[ <font style="color:#E10000; font-weight:bold;"><?php echo $order_pause; ?></font> ]</em></a>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        每页显示<input type="text" class="input-text" value="<?php echo $pageRows;?>" name="pageRows" style="width:30px;">条订单<font color="#FF0000">&nbsp;&nbsp;&nbsp;6月12号(包括12号)之前的订单请访问:&nbsp;&nbsp;&nbsp;http://114.215.147.52:81/gpadmin.php</font>
    </div>
    	<div style="color:#000;">
			<div style="float:left;">
    		
    		<input type="hidden" value="1" name="search">
    		订单状态：<select name="order_status" id="order_status">
    		<option value='9999' <?php if(9999==$order_status)echo 'selected';?>>≡ 全部  ≡</option>
				<?php foreach (OrderModel::$orderStatusCn as $status_key => $status_name):?>
				<option value='<?php echo $status_key?>' <?php if($status_key==$order_status)echo 'selected';?>><?php echo $status_name;?></option>
				<?php endforeach;?>
			  </select>
              &nbsp;&nbsp;&nbsp;付款状态：<select name="payment_status" id="payment_status">
				 	<option value='9999' <?php if(9999==$payment_status)echo 'selected';?>>≡ 全部  ≡</option>
				 	<?php foreach (OrderModel::$paymentStatus as $status_key => $status_name):?>
				<option value='<?php echo $status_key?>' <?php if(!is_null($payment_status) && $status_key==$payment_status)echo 'selected';?>><?php echo $status_name;?></option>
				<?php endforeach;?>
				 </select>
                 &nbsp;&nbsp;&nbsp;配送状态：<select name="shipping_status" id="shipping_status">
				 	<option value='9999' <?php if(9999==$shipping_status)echo 'selected';?>>≡ 全部  ≡</option>
				 	<?php foreach (OrderModel::$shippingStatus as $status_key => $status_name):?>
				<option value='<?php echo $status_key?>' <?php if(!is_null($shipping_status) && $status_key==$shipping_status)echo 'selected';?>><?php echo $status_name;?></option>
				<?php endforeach;?>
				 </select>
                 &nbsp;&nbsp;&nbsp;<select name="searchtype" id="searchtype">
					<option <?php if($searchtype==0)echo 'selected';?> value="0">订单号</option>
                    <option value="3" <?php if($searchtype==3)echo 'selected';?>>订单id</option>
					<option value="1" <?php if($searchtype==1)echo 'selected';?>>收货人</option>
					<option value="2" <?php if($searchtype==2)echo 'selected';?>>付款时间</option>
                    <option value="4" <?php if($searchtype==4)echo 'selected';?>>会员账号(email)</option>
					<option value="5" <?php if($searchtype==5)echo 'selected';?>>手机号码</option>
				</select>
				<input type="text" class="input-text" value="<?php echo $searchkeyword;?>" name="keyword" id="keyword">
                <input type="button" value="搜索" class="button" name="time_search">
	<tr class="xianshi02">
	    <th width="120">付款开始时间</th>
	    <td><input class="input-text" name="start_time" type="text" id="start_time" size="22" value='<?php echo $start_time;?>'/>
	    <span class="infoShow"></span>
	    <script type="text/javascript">
			Calendar.setup({
			weekNumbers: false,
		    inputField : "start_time",
		    trigger    : "start_time",
		    dateFormat: "%Y-%m-%d",
		    showTime: false,
		    minuteStep: 1,
		    onSelect   : function() {this.hide();}
			});
        </script>
	    </td>
	  </tr>
	  <tr class="xianshi02">
	    <th width="120">付款结束时间</th>
	    <td><input class="input-text"  name="end_time" type="text" id="end_time" size="22" value='<?php echo $end_time;?>'/>
	    <script type="text/javascript">
			Calendar.setup({
			weekNumbers: false,
		    inputField : "end_time",
		    trigger    : "end_time",
		    dateFormat: "%Y-%m-%d",
		    showTime: false,
		    minuteStep: 1,
		    onSelect   : function() {this.hide();}
			});
        </script>
	    </td>
		<input type="button" value="搜索" class="button" name="time_search">
	  </tr>
      
    <br />
	<tr class="xianshi02">
	    <th width="120">更新开始时间</th>
	    <td><input class="input-text" name="up_start_time" type="text" id="up_start_time" size="22" value='<?php echo $up_start_time;?>'/>
	    <span class="infoShow"></span>
	    <script type="text/javascript">
			Calendar.setup({
			weekNumbers: false,
		    inputField : "up_start_time",
		    trigger    : "up_start_time",
		    dateFormat: "%Y-%m-%d",
		    showTime: false,
		    minuteStep: 1,
		    onSelect   : function() {this.hide();}
			});
        </script>
	    </td>
	  </tr>
	  <tr class="xianshi02">
	    <th width="120">更新结束时间</th>
	    <td><input class="input-text"  name="up_end_time" type="text" id="up_end_time" size="22" value='<?php echo $up_end_time;?>'/>
	    <script type="text/javascript">
			Calendar.setup({
			weekNumbers: false,
		    inputField : "up_end_time",
		    trigger    : "up_end_time",
		    dateFormat: "%Y-%m-%d",
		    showTime: false,
		    minuteStep: 1,
		    onSelect   : function() {this.hide();}
			});
        </script>
	    </td>
		<input type="button" value="搜索" class="button" name="time_search">
	  </tr>
		<tr class="xianshi02" >
			<th width="120">导出定制选项时间段:</th>
			<td><input class="input-text" name="excel_start_time" type="text" id="excel_start_time" size="15" value=''/>
				<script type="text/javascript">
					Calendar.setup({
						weekNumbers: false,
						inputField : "excel_start_time",
						trigger    : "excel_start_time",
						dateFormat: "%Y-%m-%d",
						showTime: false,
						minuteStep: 1,
						onSelect   : function() {this.hide();}
					});
				</script>
			</td>
		</tr>
		<tr class="xianshi02" style="background-color: #0a8fbd">
			<th width="120">至</th>
			<td><input class="input-text"  name="excel_end_time" type="text" id="excel_end_time" size="15" value=''/>
				<script type="text/javascript">
					Calendar.setup({
						weekNumbers: false,
						inputField : "excel_end_time",
						trigger    : "excel_end_time",
						dateFormat: "%Y-%m-%d",
						showTime: false,
						minuteStep: 1,
						onSelect   : function() {this.hide();}
					});
				</script>
			</td>
		</tr>
		<tr class="xianshi02" style="background-color: #0a8fbd">
			<th width="120">类型</th>
			<td>
				<select name="modelid" id="modelid">
					<option value=''>≡ 全部类型  ≡</option>
					<?php
					if (isset($modelList) && $modelList):
						foreach ($modelList as $key => $val):
							?>
							<option value='<?php echo $key?>' <?php if($key==$modelid)echo 'selected';?>><?php echo $val;?></option>
							<?php
						endforeach;
					endif;
					?>
				</select>

			</td>
			<input type="button" value="导出订单定制选项" class="button" name="excel_export" onclick="exportAttrExcel();">
		</tr>

      
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<!--<a href="<?php echo U('order/order_email_export');?>">导出订单邮箱</a>-->
				<!--<a href="<?php echo U('order/order_list_export');?>">导出订单列表</a>-->

				<input type="hidden" value="0" name="order_count_excel" id="order_count_excel">
                <input type="hidden" value="0" name="excel" id="excel">
                <input type="hidden" value="0" name="list_measure_excel" id="list_measure_excel">
				<?php if($_SESSION['admin_user_info']['roleid']==1){ ?>
					<input type="button" value="导出订单尺寸列表" class="button" name="order_measure">
					<input type="button" value="导出订单列表" class="button" name="order_list_export">
                	<input type="button" value="导出订单统计表" class="button" name="order_count">
				<?php } ?>
    		</form>
			</div>
			<div style="float:right;">
			是否为预售订单：<select name="yushou_order_type" id="select" onchange="orderTypeUrl();">
				 	<option value='' <?php if($yushou_order_type=='')echo 'selected';?>>全部</option>
				 	<option value='1' <?php if($yushou_order_type==1)echo 'selected';?>>预售</option>
					<option value='2' <?php if($yushou_order_type==2)echo 'selected';?>>非预售</option>
				 </select>
			</div>
    	</div>
    </div>
</div>
<script type="text/javascript">
	function execlPro(){
	   $('#excel').val(1);
	   $('form[name="searchform"]').attr('action','<?php echo U('order/order_list');?>');
	   $('form[name="searchform"]').submit();
	   $('#excel').val(0);
	}
   $('input[name="order_measure"]').bind('click',function(){
	   $('#list_measure_excel').val(1); execlPro();$('#list_measure_excel').val(0); 
   })   	
   $('input[name="order_count"]').bind('click',function(){
       $('#order_count_excel').val(1); execlPro();$('#order_count_excel').val(0); 
   })
   $('input[name="order_list_export"]').bind('click',function(){
       $('form[name="searchform"]').attr('action','<?php echo U('order/order_list_export');?>');
	   $('form[name="searchform"]').submit();
   })
   $('input[name="time_search"]').bind('click',function(){
       $('form[name="searchform"]').attr('action','<?php echo U('order/order_list');?>');
	   $('form[name="searchform"]').submit();
   })              
</script>
<?php endif;?>
<div class="bk"></div>
<div class="pad_10">
<div class="table-list">
    <form action="<?php echo U('order/beach_select_edit');?>" method="post" name="myform"  id="myform" target="_blank">
    <table width="100%" cellspacing="0" >
        <thead>
            <tr>
            <th width="30" align="center"><input type="checkbox" onclick="selectall('oids[]');" id="check_box" value=""></th>
            <th width="">订单号</th>
            <th align='center' width="7%">订单总金额</th>
            <th align='center' width="7%">应付金额</th>
            <th align='left' width="15%">收货人</th>
            <th align='center' width="15%">订单状态</th>
            <th align='center' width="5%">下单时间</th>
            <th align='center' width="5%">付款时间</th>
            <th align='center' width="5%">更新时间</th>
            <th align='center' width="5%">来源</th>
			<?php if($admin_info['roleid']==1){ ?>
				<th align='center' width="15%">备注</th>
			<?php } ?>
            <th width="21%">管理操作</th>
            </tr>
        </thead>
    <tbody>
    <?php
   	if(isset($orderList) && $orderList):
   		foreach ($orderList as $k=>$v): 
   ?>
			<tr>
                    <td align="center"><input type="checkbox" name="oids[]" class="oids" value="<?php echo $v['id'];?>"></td>
					<td align='center'><?php echo $v['id']?><br /><?php echo $v['order_sn']?></td>
					<td align='center'><?php echo $v['order_amount'];?></td>
					<td align='center'><?php echo $v['pay_amount'];?></td>
					<td><?php echo $v['delivery_last_name'].($v['delivery_first_name'] ? '.'.$v['delivery_first_name']: '');?><?php echo ' [ '. ($v['delivery_phone'] ? $v['delivery_phone'] : null). ' ] ';?><br/>
					<?php echo '['. $v['delivery_country'] . ($v['delivery_province'] ? ' - '.$v['delivery_province'] : null). ' ] '. $v['delivery_address'];?>
					</td>
					<td align='center'><?php echo OrderModel::$orderStatusCn[$v['order_status']];?>,
					<?php echo OrderModel::$paymentStatus[$v['payment_status']];?>,
					<?php echo OrderModel::$shippingStatus[$v['shipping_status']];?><?php if($v['is_cheat']==2){echo ',<font color="red">疑似欺诈订单</font>';}?>
                                                <?php 
                                                if($v['shipping_status'] == OrderModel::SHIPPING_UNSHIPPED){
                                                $orderlogs = OrderModel::getOrdersLogList($v['id']);
                                                    if($orderlogs){
                                                        foreach($orderlogs as $kkk => $vvv){
                                                            if($vvv['shipping_status'] == 99){
                                                                echo ',配货中';
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                                ?>
                                        </td>
					<td align='center'><?php echo date('Y-m-d H:i:s', $v['start_time']);?></td>
					<td align='center'><?php if($v['payment_time']==0){echo '0';}else{echo date('Y-m-d H:i:s', $v['payment_time']);}?></td>
                    <td align='center'><?php if($v['update_time']==0){echo '';}else{echo date('Y-m-d H:i:s', $v['update_time']);}?></td>
                    <td align='center'><?php echo $v['is_mobile']==0?"pc":($v['is_mobile']==1?"ipad":"mobile")?></td>
					<?php if($admin_info['roleid']==1){ ?>
					<td align='center' class="admin_notes_content">
						<span class="admin_notes_show" style="display: inline;word-break:break-all; width:200px;float:left;"><?php echo $v['admin_notes'] ?></span>
						<textarea  class="admin_notes" style="display: none;"><?php echo $v['admin_notes'] ?></textarea>
						<a href="javascript:;" class="admin_notes_action" onclick="admin_notes_action($(this),'action');" style="float: right;color: red;">修改备注</a>
						<a href="javascript:;" class="admin_notes_confirm" onclick="admin_notes_action($(this),'confirm');" style="display: none" order_id="<?php echo $v['id']; ?>" >确认</a>&nbsp;
						<a href="javascript:;" class="admin_notes_cancel" onclick="admin_notes_action($(this),'cancel');" style="display: none">取消</a>
					</td>
					<?php } ?>
					<td align='center'> 
					<a href="javascript:openwinx('<?php echo U('order/order_print', 'oid='. $v['id'])?>','order_print');">打印清单</a> |  
					<a href="<?php echo U('order/order_edit', 'oid='.$v['id']);?>">查看</a> |  
					<span <?php if($_GET['del']!=1):?>style="display:none;"<?php endif;?>>
                    <a href="javascript:confirmdelurl('<?php echo U('order/order_delete', 'oid='.$v['id']);?>','确认要删除 『<?php echo $v['order_sn']?>』 吗？')">删除</a> |  
                    </span>
					<a href="javascript:locationurl('<?php echo U('order/order_list', 'user_id='.$v['user_id']);?>','确认要进入此会员 『<?php echo $v['delivery_first_name'].$v['delivery_last_name'];?>』相关订单吗？')">相关订单</a> |  
                    <a href="javascript:void(0);" onclick="cartListShow(this,<?php echo $v['id']; ?>);" class="as" >展开</a> |  
					 <?php if($v['is_size']){ ?> <img src="/admin/Tpl/public/images/check-64.png" width="20px" height="20px"   align="absmiddle" title="身型数据设置完成" /> <?php }?>
                     <?php if($buttonselect=='pause'):?>
                      <a href="javascript:openwinx('<?php echo U('order/order_log', 'order_id='.$v['id']);?>','order_log<?php echo rand(1000,9999);?>');">查看原因</a>
                     <a href="javascript:void(0);" onclick="orderPro(this,<?php echo $v['id']; ?>);" title="点击恢复，订单恢复到原列表">恢复订单</a> 
                     <?php endif;?> 
                     <?php if($v['remark']){ ?><img src="/admin/Tpl/public/images/pencil_edit.png" width="20px" height="20px" title="此订单有客户留言"   align="absmiddle" /> <?php }?>
					</td>
				</tr>
				<!-- 子信息列表 -->
               <tr style="display:none;" id="tr_<?php echo $v['id']; ?>" class="ordertrs" >
                   <td colspan = "11" id="td_<?php echo $v['id']; ?>" >
                         
                   </td>
               </tr>
         <!-- 子信息列表 -->
	<?php 
		endforeach;
		else:
		echo '<tr><td colspan="12" align="center">无订单数据</td></tr>';
		endif;
	?>
    <?php if(!$_REQUEST['is_ajax']):?>
         <tr>
             <td colspan="12">
				 <?php if($_SESSION['admin_user_info']['roleid']==1){ ?>
                 <input type="submit" class="button" name="product" value="商品清单" />
                 <input type="submit" class="button" name="logistics" value="物流清单" />
                 <input type="submit" class="button" name="pack" value="包装发货清单" />
<!--                 <input type="submit" class="button" name="tuishui" value="退税订单" />-->
<!--                 <input type="submit" class="button" name="tuishui_test" value="退税订单(测试)" />-->

                 <input type="button" class="button" name="ProductionNote" onclick="print_pro_note();" value="批量打印工厂制作单" />
                 <input type="submit" class="button" name="printMeasure" value="客户尺寸统计表" />
				 <?php } ?>
             </td>
         </tr>
    <?php endif;?>    
   </tbody>
    </table>
    </form>
<?php if(!$_REQUEST['is_ajax']):?>    
<div id="pages"><?php echo $pageShow;?></div>
<?php endif;?>
</div>
</div>
</body>
</html>
<script type="text/javascript">
//删除订单
function confirmdelurl(url,tips){
	if(confirm(tips)){
    $.ajax({
            type: 'GET',
            url: url,
            success: function(msg) {
				location.reload();
            }
           }); 
    }   
}
function print_pro_note(){
	 var oids = '';
	 $(".oids").each(function(){
	     if($(this).attr('checked')){
		    oids += ($(this).val() + ',');	
		 }
	 });
	 if(oids != ''){
	     window.open('<?php echo U('order/print_pro_note','ids=');?>'+oids+'&order_print<?php echo rand(1000,9999);?>');
	 }
}
function ButtonSelect(val){
    var hrefstr ="<?php echo U('order/order_list');?>"
/*                     +"&order_status="+$('#order_status').val()
                     +"&payment_status="+$('#payment_status').val()
                     +"&shipping_status="+$('#shipping_status').val()
                     +"&searchtype="+$('#searchtype').val()
                     +"&keyword="+$('#keyword').val()
                     +"&start_time="+$('#start_time').val()
					 +"&end_time="+$('#end_time').val()*/
					 +"&buttonselect="+val;
    location.href = hrefstr;
}

function exportAttrExcel(val){
	var excel_start_time = $("#excel_start_time").val();
	var excel_end_time = $("#excel_end_time").val();
	var model_id = $("#modelid").val();
	if(excel_start_time && excel_end_time){
		/**
		$.ajax({
			type: 'GET',
			url: "<?php echo U('Order/exportAttrExcel');?>",
			data: {"excel_start_time":excel_start_time,'excel_end_time':excel_end_time},
			dataType:'json',
			success: function(msg) {
				alert(msg.msg);
			}
		});
		*/
		var hrefstr ="<?php echo U('order/exportAttrExcel');?>"
			+"&excel_start_time="+excel_start_time
			+"&excel_end_time="+excel_end_time
			+"&model_id="+model_id;
			location.href = hrefstr;
	}else{
		alert("选择时间段");
	}
}

function orderTypeUrl()
{
	var s=document.getElementById("select").value; 
	
	window.location.href='<?php echo U('order/order_list');?>&yushou_order_type='+s; 
}

function locationurl(url){
	window.location.href=url;
}

function cartListShow(obj,id){
    $('#td_'+id).html('');
	$('.ordertrs').hide();
	ajax_zlist(id);
	$('#tr_'+id).show();
	return;
/*    if($(obj).text() == '关闭'){
        $('#tr_'+id).hide();$(obj).text('展开'); 
    }else{
    	$('.ordertrs').hide();$('.as').text('展开')
		if($('#tr_'+id).css('display')=='none'){
	        ajax_zlist(id);$('#tr_'+id).show();$(obj).text('关闭'); 
	    }else{
	    	$('#tr_'+id).hide();$(obj).text('展开'); 
	    }
    }*/
}

function ajax_zlist(id){
    $.ajax({
            type: 'POST',
            url: "<?php echo U('order/order_zlist');?>&order_id="+id,
            data: {"round":Math.random(),'order_id':id},
            dataType:'html',
            beforeSend:function(){
				$('#td_'+id).html('<div style="text-align:center;font-size:14px;">正在努力加载 ^_^ <br />子订单数据加载中，请稍后...</div>');	
			},
            success: function(msg) {
                 $('#td_'+id).html(msg);
            }
           });
}

function orderPro(obj,id){
	if(!confirm('确定此订单的暂停原因已处理完毕？')){
	   return false;
	}
    $.ajax({
		type: 'POST',
		url: "<?php echo U('order/order_pro');?>&order_id="+id,
		data: {"round":Math.random(),'order_status':'<?php echo OrderModel::ORDER_CONFIRMED;?>','action_notice':'订单从暂停状态恢复'},
		success: function(msg) {
			 if(msg != '1'){alert(msg)}{window.location.reload();}
		}
   });     
}


function admin_notes_action(_this,act){
	if(act == "action"){
		_this.hide();
		_this.siblings(".admin_notes_show").hide();
		_this.siblings(".admin_notes").show();
		_this.siblings(".admin_notes_confirm").show();
		_this.siblings(".admin_notes_cancel").show();
	} else if(act=="cancel"){ //取消
		_this.hide();
		_this.siblings(".admin_notes_confirm").hide();
		_this.siblings(".admin_notes").val(_this.siblings(".admin_notes_show").text());
		_this.siblings(".admin_notes").hide();
		_this.siblings(".admin_notes_show").show();
		_this.siblings(".admin_notes_action").show();
	} else if(act=="confirm"){ //确认
		_this.hide();
		_this.siblings(".admin_notes_cancel").hide();
		_this.siblings(".admin_notes").hide();
		_this.siblings(".admin_notes_show").show();
		_this.siblings(".admin_notes_action").show();
		var show_admin_notes_text = _this.siblings(".admin_notes_show").text();
		var admin_notes_text = _this.siblings(".admin_notes").val();
		var id = _this.attr("order_id");
		if(show_admin_notes_text==admin_notes_text){
			alert("备注未做任何修改！");
		}else{
			$.ajax({
				type: 'POST',
				url: "<?php echo U('order/edit_order_notes_by_admin');?>&order_id="+id,
				data: {'admin_notes':admin_notes_text},
				success: function(data) {
					data = JSON.parse(data);
					if(data.status==1){
						_this.siblings(".admin_notes_show").html(admin_notes_text);
					}else{
						_this.siblings(".admin_notes").val(_this.siblings(".admin_notes_show").text());
						alert(data.msg);
					}
				}
			});
		}
	}

}

</script>
